import pandas as pd
import matplotlib.pyplot as plt
import numpy as np



def plot_line(df, col_1, col_2, col_label_1, col_label_2, title):
    plt.figure(figsize=(10, 5))
    plt.plot(df.index, col_1, label=col_label_1)
    plt.plot(df.index, col_2, label=col_label_2)
    plt.title(title)
    # plt.xlabel('Index')
    # plt.ylabel('PSLL Value')
    plt.legend()
    plt.grid(True)
    plt.show()


def analysis_csv(path_csv):
    # 读取CSV文件，不跳过表头行
    df = pd.read_csv(path_csv)

    # 打印原始列名以确认它们是否正确
    print("Original column names in the DataFrame:")
    print(df.columns.tolist())

    # 删除数据部分的前两行（即索引为0和1的行）
    df = df.drop([0, 1])

    # 清理列名：移除多余空格，转为小写
    # df.columns = df.columns.str.strip().str.lower()

    # 再次打印所有列名以验证更改
    print("Cleaned column names in the DataFrame:")
    print(df.columns.tolist())

    # 计算psll, psll_NN, phase_count_diff和phase_count_diff_NN的最大值、最小值、平均值和标准差
    columns_to_calculate = ['psll', 'psll_NN', 'phase_count_diff', 'phase_count_diff_NN']
    stats = df[columns_to_calculate].agg(['min', 'max', 'mean', 'std'])

    print("Statistics:")
    print(stats)

    # 绘制psll和psll_NN的折线图
    plot_line(df, df['psll'], df['psll_NN'], 'origin', 'random', "compare PSLL")
    plot_line(df, df['phase_count_diff'], df['phase_count_diff_NN'], 'origin', 'random', "compare count diff phase")




if __name__=="__main__":
    analysis_csv("../files/multi-beam-trace/beam1/NN/theta(10,1,70)-phi(10,1,70)/theta(10,1,70)-phi(10,1,70).csv")